package security.SecurityUtil.login;/**
 * @Auther: liyipeng
 * @Date: 2020/1/9 14:25
 * @Description:
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.password.PasswordEncoder;
import util.PasswordHash;

/**
 * <p>类名: MySha1PasswordEncoder</p>
 * <p>描述:TODO</p>
 * <p>创建人: liyp</p>
 * <p>创建时间: 2020/1/9 14:25</p>
 * <p>@version 2.0  </p>
 * <p>修改内容: ......</p>
 * <p>修改说明: ......</p>
 * <p>修改时间: ......</p>
 * <p>修改人: ......</p>
 * <p>每次修改，请增加上述修改信息说明</>
 */
public class MySha1PasswordEncoder implements PasswordEncoder {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public String encode(CharSequence rawPassword) {
        logger.debug("加密时待加密的密码：" + rawPassword.toString());
        return rawPassword.toString() ;
        //return PasswordHash.getSha1(rawPassword.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        logger.debug("校验时待加密的密码：" + rawPassword.toString());
        logger.debug("校验时已加密的密码：" + encodedPassword);
        return  encodedPassword.equals(PasswordHash.getSha1(rawPassword.toString()));
    }
}